//package wu-framework-lazy-orm-solon-starter.processor;
//
//import lombok.extern.slf4j.Slf4j;
//import org.wu.framework.core.NormalUsedString;
//import org.wu.framework.core.utils.FileUtil;
//import org.wu.framework.lazy.orm.core.config.DdlConfigure;
//import org.wu.framework.lazy.orm.core.config.LazyOperationAttribute;
//import org.wu.framework.lazy.orm.core.persistence.conf.LazyDatabaseJsonMessage;
//import org.wu.framework.lazy.orm.core.persistence.conf.LazyTableEndpoint;
//import org.wu.framework.lazy.orm.core.source.SqlSourceClass;
//
//import java.io.BufferedWriter;
//import java.io.File;
//import java.net.URL;
//import java.util.List;
//
///**
// * LazyTablePostProcessor
// * DDL 操作
// *
// * @author : Jia wei Wu
// * @version 1.0
// * @date : 2022/1/2 6:23 下午
// */
//@Slf4j
//public class LazyTablePostProcessor implements Ordered, InitializingBean {
//
//    private final LazyOperationAttribute lazyOperationAttribute;
//
//    public LazyTablePostProcessor(LazyOperationAttribute lazyOperationAttribute) {
//        this.lazyOperationAttribute = lazyOperationAttribute;
//    }
//
//    @Override
//    public int getOrder() {
//        return Ordered.LOWEST_PRECEDENCE;
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//
//        BufferedWriter bufferedWriter = null;
//        DdlConfigure ddlConfigure = lazyOperationAttribute.getDdlConfigure();
//
//
//        if (ddlConfigure.isOutPutTableStructure()) {
//            URL resource = LazyTablePostProcessor.class.getResource(NormalUsedString.SLASH);
//            // 写入class文件
//            String resourceFilePrefix = resource.getFile();
//
//            String target = resourceFilePrefix.split("target")[0] + "src/main/resources/";
//            resourceFilePrefix = target + "sql" + File.separator;
//            // 创建对应的建表语句
//            bufferedWriter = FileUtil.createFileBufferedWriter(null, resourceFilePrefix, ".sql", "schema");
//        }
//        List<Class<?>> tableClass = LazyDatabaseJsonMessage.localCacheEntityClass;
//        for (Class clazz : tableClass) {
//            try {
//                if (bufferedWriter != null) {
//                    SqlSourceClass sqlSourceClass = SqlSourceClass.getInstance(clazz);
//                    LazyTableEndpoint lazyTableEndpoint = sqlSourceClass.getLazyTableEndpoint();
//
//                    String creatTableSQL = lazyTableEndpoint.creatTableSQL();
//                    bufferedWriter.write(creatTableSQL);
//                    bufferedWriter.newLine();
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//        if (bufferedWriter != null) {
//            try {
//                bufferedWriter.close();
//            } catch (Exception e) {
//
//            }
//        }
//    }
//}
